package com.china08.yxyapi.api.manage.tec.teaching.continuedu.teatrainlesson;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.mg.continuedu.YxyContinueduUserFavorite;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.mg.continuedu.YxyContinueduUserFavoriteRepository;

/**
 * 
 * @annotation: 继续教育-师训课程-取消收藏
 * @author: yaoguanglin
 */
@CrossOrigin
@RestController
public class YxyTeaTrainLessonCancelCollectController extends YxyApiBaseController {

    @Autowired
    private YxyContinueduUserFavoriteRepository yxyContinueduUserFavoriteRepository;

    @RequestMapping(value = "/api_yw/manage/tec/teaching/continuedu/teatrainlesson/cancel/collect/upd", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public RespModel process(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {

        String userId = getProfile(request, response).getId();

        String id = userId + "_" + reqModel.lessonId;
        YxyContinueduUserFavorite userFavorite = yxyContinueduUserFavoriteRepository.findById(id);
        if (userFavorite != null) {
            yxyContinueduUserFavoriteRepository.delete(userFavorite);
        }
        RespModel model = new RespModel();
        model.setMessage("取消成功");
        return model;
    }

    protected static class ReqModel extends YxyApiReqModel {
        // 课程Id
        public String lessonId;

    }

    protected static class RespModel extends YxyApiRespModel {

    }
}
